//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using EntLibContrib.Resource.Properties;

namespace EntLibContrib.Resource.Configuration.Design
{
	/// <summary>
	/// Command registrar for Data Resource providers
	/// this registers the context menu commands with the configuration console
	/// </summary>
	public sealed class DataResourceProviderCommandRegistrar: CommandRegistrar
  {
		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="T:DataResourceProviderCommandRegistrar"/> class.
		/// </summary>
		/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
		public DataResourceProviderCommandRegistrar(IServiceProvider serviceProvider) : base(serviceProvider) 
    { }
		#endregion

		#region Public Methods
		/// <summary>
		/// Register the commands.
		/// </summary>
		public override void Register ()
    {
			AddDataResourceProviderCommand();
			AddGenerateStronglyTypedResourcesCommand(typeof(DataResourceProviderNode));
			AddDefaultCommands(typeof(DataResourceProviderNode));
		}
		#endregion

		#region Private Methods
		private void AddDataResourceProviderCommand ()
    {
			ConfigurationUICommand command = ConfigurationUICommand.CreateSingleUICommand(ServiceProvider, 
																																										InternalResources.DataResourceProviderUICommandText,
																																										InternalResources.DataResourceProviderUICommandLongText, 
																																										new AddDataResourceProviderCommand(ServiceProvider), 
																																										typeof(ResourceProviderBaseNode));
			AddUICommand(command, typeof(ResourceManagerNode));                
			command.Dispose();
    }

		private void AddGenerateStronglyTypedResourcesCommand(Type resourceProviderNodeType)
		{
			ConfigurationUICommand command = new ConfigurationUICommand(ServiceProvider,
																																	InternalResources.GenerateStronglyTypedResourcesUICommandText,
																																	InternalResources.GenerateStronglyTypedResourcesUICommandLongText,
																																	CommandState.Enabled,
																																	new GenerateStronglyTypedResourcesNodeCommand(ServiceProvider),
																																	System.Windows.Forms.Shortcut.None,
																																	InsertionPoint.Action,
																																	null);
			AddUICommand(command, resourceProviderNodeType);
			command.Dispose();
		}
		#endregion
	}
}
